import React from "react";
import { User_dao } from "./SelectUser";
import { useSelector } from "react-redux";

interface Props {
    userId: string;
}
/**
 * 帖子作者
 * */
const PostAuthor = ({ userId }: Props) => {
    const data: User_dao | null = useSelector((state: any) => {
        const oldData = state.users;

        if (oldData && oldData.length > 0) {
            for (let i = 0; i < oldData.length; i++) {
                const item = oldData[i];
                if (String(item.id) === userId) {
                    return item;
                }
            }
            return null;
        } else {
            return null;
        }
    });
    return <span>{data ? data.name : "佚名"} </span>;
};

export default PostAuthor;
